// 模拟系统变量数据
export const mockVariables = [
  // 项目信息变量
  {
    id: 1,
    variable_key: "projectName",
    description: "项目的正式名称",
    data_type: "string",
    source_entity: "Project",
    source_field: "name",
    is_deprecated: false,
    example: "示例: 110kV输电线路跨越工程",
    example_code: "{{projectName}}",
    category: "项目信息"
  },
  {
    id: 2,
    variable_key: "project_startDate",
    description: "项目计划开始日期",
    data_type: "date",
    source_entity: "Project",
    source_field: "startDate",
    is_deprecated: false,
    example: "示例: 2023-06-15",
    example_code: "{{project_startDate}}",
    category: "项目信息"
  },
  {
    id: 3,
    variable_key: "project_budget",
    description: "项目预算金额(万元)",
    data_type: "number",
    source_entity: "Project",
    source_field: "budget",
    is_deprecated: false,
    example: "示例: 580",
    example_code: "{{project_budget}}万元",
    category: "项目信息"
  },
  
  // 跨越点信息变量
  {
    id: 4,
    variable_key: "crossing_location",
    description: "跨越点具体位置描述",
    data_type: "string",
    source_entity: "CrossingPoint",
    source_field: "location",
    is_deprecated: false,
    example: "示例: 某市某区某街道",
    example_code: "{{crossing_location}}",
    category: "跨越点信息"
  },
  {
    id: 5,
    variable_key: "crossingType",
    description: "跨越点类型，如公路、铁路、河流等",
    data_type: "string",
    source_entity: "CrossingPoint",
    source_field: "type",
    is_deprecated: false,
    example: "示例: 高速公路",
    example_code: "{{crossingType}}",
    category: "跨越点信息"
  },
  {
    id: 6,
    variable_key: "crossing_width",
    description: "跨越点宽度(米)",
    data_type: "number",
    source_entity: "CrossingPoint",
    source_field: "width",
    is_deprecated: false,
    example: "示例: 35",
    example_code: "{{crossing_width}}米",
    category: "跨越点信息"
  },
  
  // 施工方案信息变量
  {
    id: 7,
    variable_key: "schemeName",
    description: "施工方案的正式名称",
    data_type: "string",
    source_entity: "ConstructionScheme",
    source_field: "name",
    is_deprecated: false,
    example: "示例: 110kV线路跨越高速公路施工方案",
    example_code: "{{schemeName}}",
    category: "施工方案信息"
  },
  {
    id: 8,
    variable_key: "scheme_constructionMethod",
    description: "采用的施工方法",
    data_type: "string",
    source_entity: "ConstructionScheme",
    source_field: "constructionMethod",
    is_deprecated: false,
    example: "示例: 带电跨越",
    example_code: "{{scheme_constructionMethod}}",
    category: "施工方案信息"
  },
  {
    id: 9,
    variable_key: "scheme_totalDuration",
    description: "总施工工期(天)",
    data_type: "number",
    source_entity: "ConstructionScheme",
    source_field: "totalDuration",
    is_deprecated: false,
    example: "示例: 15",
    example_code: "{{scheme_totalDuration}}天",
    category: "施工方案信息"
  },
  
  // 系统信息变量
  {
    id: 10,
    variable_key: "system_current_date",
    description: "当前系统日期",
    data_type: "date",
    source_entity: "System",
    source_field: "current_date",
    is_deprecated: false,
    example: "示例: 2023-10-01",
    example_code: "{{system_current_date}}",
    category: "系统信息"
  },
  {
    id: 11,
    variable_key: "system_generator",
    description: "文档生成人",
    data_type: "string",
    source_entity: "System",
    source_field: "generator",
    is_deprecated: false,
    example: "示例: 张三",
    example_code: "{{system_generator}}",
    category: "系统信息"
  },
  
  // 已弃用变量
  {
    id: 12,
    variable_key: "project_old_code",
    description: "项目旧编码(已弃用)",
    data_type: "string",
    source_entity: "Project",
    source_field: "old_code",
    is_deprecated: true,
    example: "",
    example_code: "",
    category: "项目信息"
  }
];

// 模拟实体样本数据
export const mockSampleData = {
  Project: {
    id: 1,
    name: "110kV输电线路跨越工程",
    startDate: "2023-06-15",
    endDate: "2023-12-30",
    budget: 580,
    manager: "李四",
    status: "进行中"
  },
  CrossingPoint: {
    id: 1,
    name: "K12+300跨越点",
    location: "某市某区某街道",
    type: "高速公路",
    width: 35,
    voltageLevel: "110kV"
  },
  ConstructionScheme: {
    id: 1,
    name: "110kV线路跨越高速公路施工方案",
    version: "1.0",
    constructionMethod: "带电跨越",
    totalDuration: 15,
    costEstimation: 85.5,
    approvalStatus: "已批准"
  },
  System: {
    current_date: new Date().toISOString().split('T')[0],
    generator: "系统自动生成"
  }
};

// 模拟API方法
export const SystemVariableConfigMock = {
  // 模拟获取变量列表
  list: async (sort = "-created_date") => {
    // 模拟网络延迟
    await new Promise(resolve => setTimeout(resolve, 500));
    
    // 简单模拟排序
    if (sort === "-created_date") {
      return [...mockVariables].sort((a, b) => b.id - a.id);
    } else if (sort === "created_date") {
      return [...mockVariables].sort((a, b) => a.id - b.id);
    }
    
    return [...mockVariables];
  },
  
  // 模拟获取单个变量
  get: async (id) => {
    await new Promise(resolve => setTimeout(resolve, 300));
    const variable = mockVariables.find(v => v.id === id);
    if (!variable) {
      throw new Error("变量不存在");
    }
    return variable;
  },
  
  // 模拟创建变量
  create: async (variableData) => {
    await new Promise(resolve => setTimeout(resolve, 400));
    const newId = Math.max(...mockVariables.map(v => v.id)) + 1;
    const newVariable = {
      id: newId,
      ...variableData,
      is_deprecated: false,
      created_date: new Date().toISOString()
    };
    mockVariables.push(newVariable);
    return newVariable;
  },
  
  // 模拟批量创建变量
  bulkCreate: async (variablesData) => {
    await new Promise(resolve => setTimeout(resolve, 600));
    const newVariables = variablesData.map(data => {
      const newId = Math.max(...mockVariables.map(v => v.id)) + 1;
      const newVariable = {
        id: newId,
        ...data,
        is_deprecated: false,
        created_date: new Date().toISOString()
      };
      mockVariables.push(newVariable);
      return newVariable;
    });
    return newVariables;
  },
  
  // 模拟更新变量
  update: async (id, updateData) => {
    await new Promise(resolve => setTimeout(resolve, 400));
    const index = mockVariables.findIndex(v => v.id === id);
    if (index === -1) {
      throw new Error("变量不存在");
    }
    mockVariables[index] = { ...mockVariables[index], ...updateData };
    return mockVariables[index];
  },
  
  // 模拟删除变量
  delete: async (id) => {
    await new Promise(resolve => setTimeout(resolve, 300));
    const index = mockVariables.findIndex(v => v.id === id);
    if (index === -1) {
      throw new Error("变量不存在");
    }
    mockVariables.splice(index, 1);
    return true;
  }
};

// 模拟实体API
export const EntityMocks = {
  Project: {
    schema: async () => ({
      properties: {
        id: { type: "number", description: "项目ID" },
        name: { type: "string", description: "项目名称" },
        startDate: { type: "string", description: "开始日期" },
        endDate: { type: "string", description: "结束日期" },
        budget: { type: "number", description: "项目预算(万元)" },
        manager: { type: "string", description: "项目经理" },
        status: { type: "string", description: "项目状态" }
      }
    }),
    list: async (sort = "-created_date", limit = 10) => {
      await new Promise(resolve => setTimeout(resolve, 300));
      return [mockSampleData.Project];
    }
  },
  CrossingPoint: {
    schema: async () => ({
      properties: {
        id: { type: "number", description: "跨越点ID" },
        name: { type: "string", description: "跨越点名称" },
        location: { type: "string", description: "位置描述" },
        type: { type: "string", description: "跨越类型" },
        width: { type: "number", description: "宽度(米)" },
        voltageLevel: { type: "string", description: "电压等级" }
      }
    }),
    list: async (sort = "-created_date", limit = 10) => {
      await new Promise(resolve => setTimeout(resolve, 300));
      return [mockSampleData.CrossingPoint];
    }
  },
  ConstructionScheme: {
    schema: async () => ({
      properties: {
        id: { type: "number", description: "方案ID" },
        name: { type: "string", description: "方案名称" },
        version: { type: "string", description: "版本号" },
        constructionMethod: { type: "string", description: "施工方法" },
        totalDuration: { type: "number", description: "总工期(天)" },
        costEstimation: { type: "number", description: "成本估算(万元)" },
        approvalStatus: { type: "string", description: "审批状态" }
      }
    }),
    list: async (sort = "-created_date", limit = 10) => {
      await new Promise(resolve => setTimeout(resolve, 300));
      return [mockSampleData.ConstructionScheme];
    }
  }
};
    